// ------------------------------------------------------------
// @Author: ZhangPeng
// @Date: 2024年12月26日21:30
// ------------------------------------------------------------

using System;
using UnityEngine;

public class UpdatableData : ScriptableObject
{
    public event System.Action OnValuesUpdated;

    public bool autoUpdate;

    # if UNITY_EDITOR
    protected virtual void OnValidate()
    {
        if (autoUpdate)
        {
            UnityEditor.EditorApplication.update += NotifyOfUpdatedValues;
        }
    }

    public void NotifyOfUpdatedValues()
    {
        UnityEditor.EditorApplication.update -= NotifyOfUpdatedValues;
        if (OnValuesUpdated!=null)
        {
            OnValuesUpdated();
        }
    }
    
    #endif
}